/***********************************************************************************************//**
 * \file   app.c
 * \brief  Event handling and application code for Empty NCP Host application example
 ***************************************************************************************************
 * <b> (C) Copyright 2016 Silicon Labs, http://www.silabs.com</b>
 ***************************************************************************************************
 * This file is licensed under the Silabs License Agreement. See the file
 * "Silabs_License_Agreement.txt" for details. Before using this software for
 * any purpose, you must agree to the terms of that agreement.
 **************************************************************************************************/

/* standard library headers */
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>

/* BG stack headers */
#include "bg_types.h"
#include "gecko_bglib.h"

/* Own header */
#include "app.h"

/***********************************************************************************************//**
 *  \brief  Event handler function.
 *  \param[in] evt Event pointer.
 **************************************************************************************************/
void appHandleEvents(struct gecko_cmd_packet *evt)
{
	if (NULL == evt) 
	{
		return;
	}

	/* Handle events */
	switch (BGLIB_MSG_ID(evt->header)) 
	{
		case gecko_evt_system_boot_id:
        {
			printf("System booted. Starting advertising. \n");

            uint8_t *p = gecko_cmd_system_get_bt_address()->address.addr;
            printf("Local MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n",p[5],p[4],p[3],p[2],p[1],p[0]);

			/* Set advertising parameters. 100ms advertisement interval. All channels used.
			* The first two parameters are minimum and maximum advertising interval, both in
			* units of (milliseconds * 1.6). The third parameter '7' sets advertising on all channels. */
			//gecko_cmd_le_gap_set_adv_parameters(160, 160, 7);

			/* Start general advertising and enable connections. */
			//gecko_cmd_le_gap_set_mode(le_gap_general_discoverable, le_gap_undirected_connectable);

        }
        break;

        case gecko_evt_hardware_soft_timer_id:
            switch (evt->data.evt_hardware_soft_timer.handle) 
            {
                case 7:
                    printf("timer\r\n");
                break;
                default:
                break;
            }
        break;

		case gecko_evt_le_connection_closed_id:
		
			/* Restart general advertising and re-enable connections after disconnection. */
			gecko_cmd_le_gap_set_mode(le_gap_general_discoverable, le_gap_undirected_connectable);

        break;

		default:
        break;
  }
}

